package cn.edu.scau.cmi.liangzaoqing.copyFileByFile;

import static org.junit.jupiter.api.Assertions.*;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class CopyFileByFile {
	private String projectName;
	private String cmiPages;
	private String javaPackage;
	private String sourceProjectDirectionary;
	private String targetProjectDirectionary;
	private String cmiDomain;
	private String cmiDao;
	private String cmiController;
	private String cmiRestController;
	private String cmiPagination;
	private String cmiPropertyEditor;
	private String cmiService;
	private String cmiUtil;
	private String resource;
	private String resourcesBundles;
	private String cmiBase;
	private String cmiBaseBean;
	private String cmiBasePropertyEditor;
	private String cmiBaseServiced;
	private String cmiBaseController;
	private String cmiBaseRestController;
//	TODO　测试完成后使用Spring依赖注入
	@BeforeEach
	void setUp() throws Exception {
		Properties properties = new Properties();
		InputStream input = new BufferedInputStream(new FileInputStream("E:\\Workspace\\git\\scauCmiScaffolding\\test\\copy\\file.properties"));
		properties.load(input);
//		基本属性部分
		sourceProjectDirectionary = properties.getProperty("sourceProjectDirectionary");
		targetProjectDirectionary = properties.getProperty("targetProjectDirectionary");
		projectName = properties.getProperty("projectName");
		javaPackage = properties.getProperty("javaPackage");
//		Java基础类部分
		cmiBase = properties.getProperty("cmiBase");
		cmiBaseBean = properties.getProperty("cmiBaseBean");
		cmiBasePropertyEditor = properties.getProperty("cmiBasePropertyEditor");
		cmiBaseServiced = properties.getProperty("cmiBaseServiced");
		cmiBaseController = properties.getProperty("cmiBaseController");
		cmiBaseRestController = properties.getProperty("cmiBaseRestController");
		cmiUtil = properties.getProperty("cmiUtil");
//		java核心类部分
		cmiController = properties.getProperty("cmiController");
		cmiRestController = properties.getProperty("cmiRestController");
		cmiDao = properties.getProperty("cmiDao");
		cmiDomain = properties.getProperty("cmiDomain");
		cmiPagination = properties.getProperty("cmiPagination");
		cmiPropertyEditor = properties.getProperty("cmiPropertyEditor");
		cmiService = properties.getProperty("cmiService");
		

//		资源部分		
		resource = properties.getProperty("resource");
		resourcesBundles = properties.getProperty("resourcesBundles");
		
//		页面部分
		cmiPages = properties.getProperty("cmiPages");

//		properties.list(System.out);

//		System.out.println(cmiPages);
	}

	@Test
	void copyBase() throws IOException {
		String srcBaseDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiBase;
		String destBaseDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiBase;
		FileUtils.copyDirectory(new File(srcBaseDirectionary), new File(destBaseDirectionary));
		System.out.println(srcBaseDirectionary);
		System.out.println(destBaseDirectionary);
		System.out.println("复制Base文件成功！！！");
	}
	
	
	@Test
	void copyBaseBean() throws IOException {
		String srcBaseBeanDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiBaseBean;
		String destBaseBeanDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiBaseBean;
		FileUtils.copyDirectory(new File(srcBaseBeanDirectionary), new File(destBaseBeanDirectionary));
		System.out.println(srcBaseBeanDirectionary);
		System.out.println(destBaseBeanDirectionary);
		System.out.println("复制BaseBean文件成功！！！");
	}
	
	@Test
	void copyBasePropertyEditor() throws IOException {
		String srcBasePropertyEditorDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiBasePropertyEditor;
		String destBasePropertyEditorDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiBasePropertyEditor;
		FileUtils.copyDirectory(new File(srcBasePropertyEditorDirectionary), new File(destBasePropertyEditorDirectionary));
		System.out.println(srcBasePropertyEditorDirectionary);
		System.out.println(destBasePropertyEditorDirectionary);
		System.out.println("复制BasePropertyEditor文件成功！！！");
	}
	
	@Test
	void copyBaseService() throws IOException {
		String srcBaseServiceDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiBaseServiced;
		String destBaseServiceDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiBaseServiced;
		FileUtils.copyDirectory(new File(srcBaseServiceDirectionary), new File(destBaseServiceDirectionary));
		System.out.println(srcBaseServiceDirectionary);
		System.out.println(destBaseServiceDirectionary);
		System.out.println("复制BaseService文件成功！！！");
	}

	@Test
	void copyBaseController() throws IOException {
		String srcBaseControllerDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiBaseController;
		String destBaseControllerDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiBaseController;
		FileUtils.copyDirectory(new File(srcBaseControllerDirectionary), new File(destBaseControllerDirectionary));
		System.out.println(srcBaseControllerDirectionary);
		System.out.println(destBaseControllerDirectionary);
		System.out.println("复制BaseController文件成功！！！");
	}
	
	@Test
	void copyBaseRestController() throws IOException {
		String srcBaseRestControllerDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiBaseRestController;
		String destBaseRestControllerDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiBaseRestController;
		FileUtils.copyDirectory(new File(srcBaseRestControllerDirectionary), new File(destBaseRestControllerDirectionary));
		System.out.println(srcBaseRestControllerDirectionary);
		System.out.println(destBaseRestControllerDirectionary);
		System.out.println("复制BaseRestController文件成功！！！");
	}
	
	
	
	
	
	
	
	@Test
	void copyDomain() throws IOException {
		String srcDomainDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiDomain;
		String destDomainDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiDomain;
		FileUtils.copyDirectory(new File(srcDomainDirectionary), new File(destDomainDirectionary));
		System.out.println(srcDomainDirectionary);
		System.out.println(destDomainDirectionary);
		System.out.println("复制Domain类文件成功！！！");
	}
	
	

	
	
	@Test
	void copyDao() throws IOException {
		String srcDaoDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiDao;
		String destDaoDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiDao;
		FileUtils.copyDirectory(new File(srcDaoDirectionary), new File(destDaoDirectionary));
		System.out.println(srcDaoDirectionary);
		System.out.println(destDaoDirectionary);
		System.out.println("复制Dao文件成功！！！");
	}
	
	@Test
	void copyController() throws IOException {
		String srcControllerDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiController;
		String destControllerDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiRestController;
		FileUtils.copyDirectory(new File(srcControllerDirectionary), new File(destControllerDirectionary));
		System.out.println(srcControllerDirectionary);
		System.out.println(destControllerDirectionary);
		System.out.println("复制Controller文件成功！！！");
	}
	
	@Test
	void copyRestController() throws IOException {
		String srcRestControllerDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiRestController;
		String destRestControllerDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiRestController;
		FileUtils.copyDirectory(new File(srcRestControllerDirectionary), new File(destRestControllerDirectionary));
		System.out.println(srcRestControllerDirectionary);
		System.out.println(destRestControllerDirectionary);
		System.out.println("复制RestController文件成功！！！");
	}
	
	@Test
	void copyPropertyEditor() throws IOException {
		String srcPropertyEditorDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiPropertyEditor;
		String destPropertyEditorDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiPropertyEditor;
		FileUtils.copyDirectory(new File(srcPropertyEditorDirectionary), new File(destPropertyEditorDirectionary));
		System.out.println(srcPropertyEditorDirectionary);
		System.out.println(destPropertyEditorDirectionary);
		System.out.println("复制PropertyEditor文件成功！！！");
	}
	
	@Test
	void copyPagination() throws IOException {
		String srcPaginationDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiPagination;
		String destPaginationDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiPagination;
		FileUtils.copyDirectory(new File(srcPaginationDirectionary), new File(destPaginationDirectionary));
		System.out.println(srcPaginationDirectionary);
		System.out.println(destPaginationDirectionary);
		System.out.println("复制Pagination文件成功！！！");
	}
	
	@Test
	void copyService() throws IOException {
		String srcServiceDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiService;
		String destServiceDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiService;
		FileUtils.copyDirectory(new File(srcServiceDirectionary), new File(destServiceDirectionary));
		System.out.println(srcServiceDirectionary);
		System.out.println(destServiceDirectionary);
		System.out.println("复制Service文件成功！！！");
	}
	
	@Test
	void copyUtil() throws IOException {
		String srcUtilDirectionary=sourceProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiUtil;
		String destUtilDirectionary=targetProjectDirectionary+"/"+"cmi"+"/"+javaPackage+"/"+projectName+"/"+cmiUtil;
		FileUtils.copyDirectory(new File(srcUtilDirectionary), new File(destUtilDirectionary));
		System.out.println(srcUtilDirectionary);
		System.out.println(destUtilDirectionary);
		System.out.println("复制Util文件成功！！！");
	}
	
	@Test
	void copyResource() throws IOException {
		String srcResourceDirectionary=sourceProjectDirectionary+"/"+resource;
		String destResourceDirectionary=targetProjectDirectionary+"/"+resource;
		FileUtils.copyDirectory(new File(srcResourceDirectionary), new File(destResourceDirectionary));
		System.out.println(srcResourceDirectionary);
		System.out.println(destResourceDirectionary);
		System.out.println("复制Resource文件成功！！！");
	}
	
	@Test
	void copyResourcesBundles() throws IOException {
		String srcResourceBundlesDirectionary=sourceProjectDirectionary+"/"+resourcesBundles;
		String destResourceBundlesDirectionary=targetProjectDirectionary+"/"+resourcesBundles;
		FileUtils.copyDirectory(new File(srcResourceBundlesDirectionary), new File(destResourceBundlesDirectionary));
		System.out.println(srcResourceBundlesDirectionary);
		System.out.println(destResourceBundlesDirectionary);
		System.out.println("复制Resource文件成功！！！");
	}
	
	
	@Test
	void copyJsp() throws IOException {

		FileUtils.copyDirectory(new File(sourceProjectDirectionary + "/" + cmiPages), new File(targetProjectDirectionary + "/" + cmiPages));
		System.out.println("复制jsp文件成功！！！");
	}
	
	

}
